Skip to contentSkip to conversation

Change in openvpn[master]: PUSH_UPDATE server: bug-fix, reset buffer after processing

Openvpn-devel In review mrbff (Code Review) 2 participants 8 messages Oct 10, 2025 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): gerrit.1760090860000.I41d08a9a2e79ac1f1104e72dd5b7b7617e2071a0@...2715...

#1 lore raw

Attention is currently required from: flichtenheld, plaisthos.

Hello plaisthos, flichtenheld,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1264?usp=email

to review the following change.

Change subject: PUSH_UPDATE server: bug-fix, reset buffer after processing
......................................................................

PUSH_UPDATE server: bug-fix, reset buffer after processing

In the send_single_push_update() function the buffer containing the message was not reset after processing, so o in a push-update-broad the messages sent starting from the second client would have been shrunk (offset advanced and size decreased).

Change-Id I41d08a9a2e79ac1f1104e72dd5b7b7617e2071a0

---
M src/openvpn/push_util.c

1 file changed, 6 insertions(+), 1 deletion(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/64/1264/1

src/openvpn/push_util.c +6 -1
index 9138bdb..43f2cb3 100644
@@ -171,8 +171,13 @@
          * to check the return value here because we just want to `advance`,
          * meaning we skip the `push_update_cmd' we added earlier.
          */
+        int original_size = msgs[i].len;
         buf_string_compare_advance(&msgs[i], push_update_cmd);
-        if (process_incoming_push_update(c, pull_permission_mask(c), option_types_found, &msgs[i], true) == PUSH_MSG_ERROR)
+        int ret = process_incoming_push_update(c, pull_permission_mask(c), option_types_found, &msgs[i], true);
+        /* We reset the processed buffer */
+        msgs[i].offset = 0;
+        msgs[i].len = original_size;
+        if (ret == PUSH_MSG_ERROR)
         {
             msg(M_WARN, "Failed to process push update message sent to client ID: %u",
                 c->c2.tls_multi ? c->c2.tls_multi->peer_id : UINT32_MAX);

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1264?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I41d08a9a2e79ac1f1104e72dd5b7b7617e2071a0
Gerrit-Change-Number: 1264
Gerrit-PatchSet: 1
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>

#2 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

Hello flichtenheld, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1264?usp=email

to look at the new patch set (#3).

Change subject: PUSH_UPDATE server: bug-fix, reset buffer after processing
......................................................................

PUSH_UPDATE server: bug-fix, reset buffer after processing

In the send_single_push_update() function the buffer containing the message was not reset after processing, so o in a push-update-broad the messages sent starting from the second client would have been shrunk (offset advanced and size decreased).

Change-Id I41d08a9a2e79ac1f1104e72dd5b7b7617e2071a0

---
M src/openvpn/push_util.c

1 file changed, 4 insertions(+), 2 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/64/1264/3

src/openvpn/push_util.c +4 -2
index f306104..eee68da 100644
@@ -171,8 +171,10 @@
          * to check the return value here because we just want to `advance`,
          * meaning we skip the `push_update_cmd' we added earlier.
          */
-        buf_string_compare_advance(&msgs[i], push_update_cmd);
-        if (process_incoming_push_update(c, pull_permission_mask(c), option_types_found, &msgs[i], true) == PUSH_MSG_ERROR)
+        struct buffer buf;
+        buf_set_read(&buf, (uint8_t *)BSTR(&msgs[i]), BLEN(&msgs[i]));
+        buf_string_compare_advance(&buf, push_update_cmd);
+        if (process_incoming_push_update(c, pull_permission_mask(c), option_types_found, &buf, true) == PUSH_MSG_ERROR)
         {
             msg(M_WARN, "Failed to process push update message sent to client ID: %u",
                 c->c2.tls_multi ? c->c2.tls_multi->peer_id : UINT32_MAX);

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1264?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I41d08a9a2e79ac1f1104e72dd5b7b7617e2071a0
Gerrit-Change-Number: 1264
Gerrit-PatchSet: 3
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>

#3 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

Hello flichtenheld, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1264?usp=email

to look at the new patch set (#4).

Change subject: PUSH_UPDATE server: bug-fix, reset buffer after processing
......................................................................

PUSH_UPDATE server: bug-fix, reset buffer after processing

In the send_single_push_update() function the buffer containing the message was not reset after processing, so o in a push-update-broad the messages sent starting from the second client would have been shrunk (offset advanced and size decreased).

Change-Id I41d08a9a2e79ac1f1104e72dd5b7b7617e2071a0

---
M src/openvpn/push_util.c

1 file changed, 5 insertions(+), 2 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/64/1264/4

src/openvpn/push_util.c +5 -2
index f306104..b475d2e 100644
@@ -170,9 +170,12 @@
          * inside `process_incoming_push_msg()`. However, we don't need
          * to check the return value here because we just want to `advance`,
          * meaning we skip the `push_update_cmd' we added earlier.
+         * Also we need to make a temporary copy so we can buf_advance()
+         * without modifying original buffer.
          */
-        buf_string_compare_advance(&msgs[i], push_update_cmd);
-        if (process_incoming_push_update(c, pull_permission_mask(c), option_types_found, &msgs[i], true) == PUSH_MSG_ERROR)
+        struct buffer tmp_msg = msgs[i];
+        buf_string_compare_advance(&tmp_msg, push_update_cmd);
+        if (process_incoming_push_update(c, pull_permission_mask(c), option_types_found, &tmp_msg, true) == PUSH_MSG_ERROR)
         {
             msg(M_WARN, "Failed to process push update message sent to client ID: %u",
                 c->c2.tls_multi ? c->c2.tls_multi->peer_id : UINT32_MAX);

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1264?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I41d08a9a2e79ac1f1104e72dd5b7b7617e2071a0
Gerrit-Change-Number: 1264
Gerrit-PatchSet: 4
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>

#4 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, mrbff, plaisthos.

cron2 has posted comments on this change by mrbff. ( http://gerrit.openvpn.net/c/openvpn/+/1264?usp=email )

Change subject: PUSH_UPDATE server: bug-fix, reset buffer after processing
......................................................................

Patch Set 4: Code-Review+2

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1264?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I41d08a9a2e79ac1f1104e72dd5b7b7617e2071a0
Gerrit-Change-Number: 1264
Gerrit-PatchSet: 4
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: mrbff <[email protected]...>
Gerrit-Comment-Date: Fri, 10 Oct 2025 14:19:48 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes

#5 lore raw

PATCH v4 1/1 PUSH_UPDATE server: bug-fix, reset buffer after processing

In reply to a message not in the archive

From: Marco Baffo <[email protected]...>

In the send_single_push_update() function the buffer containing the message was not reset after processing, so o in a push-update-broad the messages sent starting from the second client would have been shrunk (offset advanced and size decreased).

Change-Id I41d08a9a2e79ac1f1104e72dd5b7b7617e2071a0

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1264
---

This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1264
This mail reflects revision 4 of this Change.

Acked-by according to Gerrit (reflected above):
Gert Doering <[email protected]...>

src/openvpn/push_util.c +5 -2
index f306104..b475d2e 100644
@@ -170,9 +170,12 @@
          * inside `process_incoming_push_msg()`. However, we don't need
          * to check the return value here because we just want to `advance`,
          * meaning we skip the `push_update_cmd' we added earlier.
+         * Also we need to make a temporary copy so we can buf_advance()
+         * without modifying original buffer.
          */
-        buf_string_compare_advance(&msgs[i], push_update_cmd);
-        if (process_incoming_push_update(c, pull_permission_mask(c), option_types_found, &msgs[i], true) == PUSH_MSG_ERROR)
+        struct buffer tmp_msg = msgs[i];
+        buf_string_compare_advance(&tmp_msg, push_update_cmd);
+        if (process_incoming_push_update(c, pull_permission_mask(c), option_types_found, &tmp_msg, true) == PUSH_MSG_ERROR)
         {
             msg(M_WARN, "Failed to process push update message sent to client ID: %u",
                 c->c2.tls_multi ? c->c2.tls_multi->peer_id : UINT32_MAX);
#6 lore raw

[Openvpn-devel] [PATCH applied] Re: PUSH_UPDATE server: bug-fix, reset buffer after processing

Discovered the problem while testing #1255 with multiple clients online at the same time, with different capabilities - and it only sent anything to the very first (capable) client, and then "empty string" because the buffer in msgs[i] was buf_advance()'d and it shouldn't have been...

So this fixes things by doing a shallow copy to a temp "buffer", which is safe as long as no writes to the memory is done - reading & advancing the pointers is fine (we discussed various approaches on IRC, as can be seen in v1/v3/v4 in gerrit ;-) - and a "make documentation for this API" issue also appeared...).

Tested this + #1255, and now things behave correctly.

Your patch has been applied to the master branch.

commit 107f80b8e3102cca3a2cc008d37895f96ec2f17c

Author: Marco Baffo
Date:   Fri Oct 10 16:19:56 2025 +0200
     PUSH_UPDATE server: bug-fix, reset buffer after processing

     Signed-off-by: Marco Baffo <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1264
     Message-Id: <[email protected]...>
     URL: https://sourceforge.net/p/openvpn/mailman/message/59244933/
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#7 lore raw
In reply to a message not in the archive

cron2 has uploaded a new patch set (#5) to the change originally created by mrbff. ( http://gerrit.openvpn.net/c/openvpn/+/1264?usp=email )

The following approvals got outdated and were removed:
Code-Review+2 by cron2

Change subject: PUSH_UPDATE server: bug-fix, reset buffer after processing
......................................................................

PUSH_UPDATE server: bug-fix, reset buffer after processing

In the send_single_push_update() function the buffer containing the message was not reset after processing, so o in a push-update-broad the messages sent starting from the second client would have been shrunk (offset advanced and size decreased).

Change-Id I41d08a9a2e79ac1f1104e72dd5b7b7617e2071a0

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1264
Message-Id: <[email protected]...>
URL: https://sourceforge.net/p/openvpn/mailman/message/59244933/

---
M src/openvpn/push_util.c

1 file changed, 5 insertions(+), 2 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/64/1264/5

src/openvpn/push_util.c +5 -2
index f306104..b475d2e 100644
@@ -170,9 +170,12 @@
          * inside `process_incoming_push_msg()`. However, we don't need
          * to check the return value here because we just want to `advance`,
          * meaning we skip the `push_update_cmd' we added earlier.
+         * Also we need to make a temporary copy so we can buf_advance()
+         * without modifying original buffer.
          */
-        buf_string_compare_advance(&msgs[i], push_update_cmd);
-        if (process_incoming_push_update(c, pull_permission_mask(c), option_types_found, &msgs[i], true) == PUSH_MSG_ERROR)
+        struct buffer tmp_msg = msgs[i];
+        buf_string_compare_advance(&tmp_msg, push_update_cmd);
+        if (process_incoming_push_update(c, pull_permission_mask(c), option_types_found, &tmp_msg, true) == PUSH_MSG_ERROR)
         {
             msg(M_WARN, "Failed to process push update message sent to client ID: %u",
                 c->c2.tls_multi ? c->c2.tls_multi->peer_id : UINT32_MAX);

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1264?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I41d08a9a2e79ac1f1104e72dd5b7b7617e2071a0
Gerrit-Change-Number: 1264
Gerrit-PatchSet: 5
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>

#8 lore raw
In reply to a message not in the archive

cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/1264?usp=email )

Change subject: PUSH_UPDATE server: bug-fix, reset buffer after processing
......................................................................

PUSH_UPDATE server: bug-fix, reset buffer after processing

In the send_single_push_update() function the buffer containing the message was not reset after processing, so o in a push-update-broad the messages sent starting from the second client would have been shrunk (offset advanced and size decreased).

Change-Id I41d08a9a2e79ac1f1104e72dd5b7b7617e2071a0

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1264
Message-Id: <[email protected]...>
URL: https://sourceforge.net/p/openvpn/mailman/message/59244933/

---
M src/openvpn/push_util.c

1 file changed, 5 insertions(+), 2 deletions(-)
src/openvpn/push_util.c +5 -2
index f306104..b475d2e 100644
@@ -170,9 +170,12 @@
          * inside `process_incoming_push_msg()`. However, we don't need
          * to check the return value here because we just want to `advance`,
          * meaning we skip the `push_update_cmd' we added earlier.
+         * Also we need to make a temporary copy so we can buf_advance()
+         * without modifying original buffer.
          */
-        buf_string_compare_advance(&msgs[i], push_update_cmd);
-        if (process_incoming_push_update(c, pull_permission_mask(c), option_types_found, &msgs[i], true) == PUSH_MSG_ERROR)
+        struct buffer tmp_msg = msgs[i];
+        buf_string_compare_advance(&tmp_msg, push_update_cmd);
+        if (process_incoming_push_update(c, pull_permission_mask(c), option_types_found, &tmp_msg, true) == PUSH_MSG_ERROR)
         {
             msg(M_WARN, "Failed to process push update message sent to client ID: %u",
                 c->c2.tls_multi ? c->c2.tls_multi->peer_id : UINT32_MAX);

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1264?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I41d08a9a2e79ac1f1104e72dd5b7b7617e2071a0
Gerrit-Change-Number: 1264
Gerrit-PatchSet: 5
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>